package com.example.back.service;

import com.example.back.entity.User;
import com.example.back.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;

@Service
public class UserService {
    LocalDateTime currentDateTime = LocalDateTime.now() .truncatedTo(ChronoUnit.MINUTES);
    @Autowired
    private UserMapper userMapper;
    public int addUser(User user){
        user.setZcsj(currentDateTime.toString());
        return userMapper.addUser(user);
    }
    public int deleteUser(Integer id){
        return userMapper.deleteUser(id);
    }
    public int updateUser(User user){
        return userMapper.updateUser(user);
    }
    public User queryUserById(Integer id){
        return userMapper.queryUserById(id);
    }
    public ArrayList<User> selectUsers(User user){
        return userMapper.selectUsers(user);
    }
    public User selectUser(User user){
        return userMapper.selectUser(user);
    }
    public User queryUserByYhm(String yhm){
        return userMapper.queryUserByYhm(yhm);
    }
    public User queryUserByPhone(String phone){
        return userMapper.queryUserByPhone(phone);
    }
    public User queryUserByEmail(String email){
        return userMapper.queryUserByEmail(email);
    }

    public ArrayList<User> queryUserByFanId(Integer userId){
        return userMapper.queryUserByFanId(userId);
    }
}
